﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;

namespace Screenshot2Disk
{
    public class ImageHelper
    {
        public static void SaveImage(Image image, string path, ImageFormat format, int compression)
        {
            var imgformat = format.ToString().ToLower();
            var filename = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "." + imgformat;
            filename = Path.Combine(path, filename);

            var codecs = ImageCodecInfo.GetImageEncoders();
            var ici = codecs.Where(c => c.MimeType == "image/" + imgformat).First();

            EncoderParameters ep = null;
            ep = new EncoderParameters();
            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)compression);

            image.Save(filename, ici, ep);
        }
    }
}
